<template>
  <div class="detail">
    <Banner :banners="banners"></Banner>
    <div class="header">
        <div>
            <img :src="detail.avatar" alt="">
            <span>{{detail.author}}</span>
            <span>发表于</span>
            <span>{{detail.dateTime}}</span>
        </div>
        <h1>{{detail.title}}</h1>
        <img class="collect" :src="detail.collected?url1:url2" alt="">
        <img class="share" src="../../../assets/images/icon/share.png" alt="">
    </div>

    <div class="content">
        {{detail.detail}}
    </div>
  </div>
</template>

<script>
import Banner from "../../../components/Banner";
export default {
  components: { Banner },
  data() {
    return {
      detail: {},
      banners: [],
      url1:require("../../../assets/images/icon/collection.png"),
      url2:require("../../../assets/images/icon/collection-anti.png"),
    };
  },
  mounted() {
    var { id } = this.$route.params;
    this.$http(`http://122.112.161.135:4000/api/articleDetail?id=${id}`).then(
      (res) => {
        this.detail = res.data.res[0];
      }
    );
    this.$http(`http://122.112.161.135:4000/api/banner`).then((res) => {
      this.banners = res.data.res.map(item=>{
          item.imageUrl = item.imgUrl;
          return item
      });
    });
  },
};
</script>

<style scoped>
.header{
    margin: 0.3rem 0.5rem;
    border-bottom: 1px solid #ccc;
    position: relative;
}
.header>div{
    display: flex;
    align-items: center;
}
.header>div>img{
    width: 1.5rem;
    height: 1.5rem;
}
.header span{
    margin-left: 0.3rem;
}
.header h1{
    font-size: 0.6rem;
    font-weight: 800;
    line-height: 0.8rem;
    margin: 0.3rem 0 1rem;
}
.header>img{
    width: 1rem;
    height: 1rem;
    position: absolute;
    bottom: -0.5rem;
}
.collect{
    right: 1.2rem;
}
.share{
    right: 0;
}
.content{
    padding: 1rem 0.5rem;
    line-height: 0.6rem;
    font-size: 0.2rem;
    color: #666;
}
</style>